package singleinstance;

public class Test {
    //设计单例类：确保某个类只能创建一个对象
    //好处：避免浪费内存
    public static void main(String[] args) {
        M m = M.getInstance();
        M m1 = M.getInstance();

        System.out.println(m);
        System.out.println(m1);
        System.out.println(m==m1);

        N n = N.getInstance();
        N n1 = N.getInstance();

        System.out.println(n==n1);//地址一样
        System.out.println(n);
        System.out.println(n1);
    }

}
